	
	<?php
		function set_val($obj, $val, $return='echo')
		{
			if(isset($obj))
				if(isset($obj->$val))
					if($return=='echo')
						echo($obj->$val);
					else
						return $obj->$val;
		}
	?>

 <link rel="stylesheet" href="<?php echo $this->config->item('css')?>/jquery.multiselect.css"> <!--  -->
 <link rel="stylesheet" href="<?php echo $this->config->item('css')?>/jquery.multiselect.filter.css"> <!--  -->

<script src="<?php echo $this->config->item('js')?>/jquery.multiselect.min.js"></script>
<script src="<?php echo $this->config->item('js')?>/jquery.multiselect.filter.js"></script>

					<div>
						<br>
						
					<form id="form" class="block-content form" action="<?php echo site_url('contacts/save')?>" method="post">
						<input type="hidden" id="id" name="id" value="<?php set_val($contact,'id')?>" />
						<div class="_25">
							<p><label for="title">Title</label>
								<select id="title" name="title" class="required" >
										<option value="">Select a title</option>
									<?php foreach($titles_list as $title):?>
										<option <?php if(set_val($contact,'title','return')==$title->id) echo 'selected="selected"';?> value="<?php echo $title->id?>"><?php echo $title->en_name.' - '.$title->name?></option>
									<?php endforeach;?>
								</select>
							</p>
						</div>
						<div class="_100">
							<p><label for="name_ar">Arabic Name</label><input id="name_ar" name="name_ar" class="required" type="text" value="<?php set_val($contact,'name_ar')?>" /></p>
						</div>
						
						<div class="_100">
							<p><label for="name_en">English Name</label><input id="name_en" name="name_en" class="required" type="text" value="<?php set_val($contact,'name_en')?>" /></p>
						</div>
						
						<div class="_50">
							<p>
								<span class="label">Gender</span>
								<label><input type="radio" name="gender" value="M" <?php if(set_val($contact,'gender','return')=='M') echo 'checked ';?> class="required" /> Male</label>
								<label><input type="radio" name="gender" value="F" <?php if(set_val($contact,'gender','return')=='F') echo 'checked ';?> class="required" /> Female</label>
							</p>
						</div>						
												
						<div class="_50">
							<p>
								<span class="label">Lang</span>
								<label><input type="radio" name="lang" value="ar" <?php if(set_val($contact,'lang','return')=='ar') echo 'checked ';?> class="required" /> Arabic</label>
								<label><input type="radio" name="lang" value="en" <?php if(set_val($contact,'lang','return')=='en') echo 'checked ';?> class="required" /> English</label>
							</p>
						</div>						
												
						<div class="_100">
							<p><label for="email">Email</label><input id="email" name="email" class="required email" type="text" value="<?php set_val($contact,'email')?>" /></p>
						</div>
						
						
						<?php /**** COMPANY ****/ ?>
						
						
						<?php if($load_all_companies):?>
						<div class="_100">
							<p><label for="company">Company</label>
							<select name="company" id="company" class="">
								<option value="">Select Company</option>
								<?php foreach($com_list as $com):?>
									<option <?php if(set_val($contact,'company','return')==$com->id) echo 'selected="selected"';?> value="<?php echo $com->id?>"><?php echo $com->name?></option>
								<?php endforeach;?>
							</select>
							</p>
						</div>
						<?php endif;?>
						
						<?php if(!$load_all_companies):?>
						<div class="_100">
							<p><label for="company">Company</label>
							<select name="company" id="company" class="required">
								<option selected="selected" value="<?php echo $com_list->id?>"><?php echo $com_list->name?></option>
							</select>	
							</p>
						</div>
						<?php endif;?>
						
						<?php /**** END COMPANY ****/ ?>
						
						<div class="_100">
							<p><label for="country">Country</label>
							<select name="country" id="country" class="required">
								<option value="">Select Country</option>
								<?php foreach($this->config->item('en_countries') as $key=>$value):?>
									<option <?php if(set_val($contact,'country','return')==$key) echo 'selected="selected"';?> value="<?php echo $key?>"><?php echo $value?></option>
								<?php endforeach;?>
							</select>
							</p>
						</div>
						
						<div class="_100">
							<p><label for="city">City</label><input id="city" name="city" class="required" type="text" value="<?php set_val($contact,'city')?>" /></p>
						</div>
						
						<div class="_50">
							<p><label for="mobile1">Mobile 1</label><input id="mobile1" name="mobile1" class="required" type="text" value="<?php set_val($contact,'mobile1')?>" /></p>
						</div>
						
						<div class="_50">
							<p><label for="phone2">Mobile 2</label><input id="mobile2" name="mobile2" class="" type="text" value="<?php set_val($contact,'mobile2')?>" /></p>
						</div>
						
						<div class="_50">
							<p><label for="home_phone">Home Phone </label><input id="home_phone" name="home_phone" class="" type="text" value="<?php set_val($contact,'home_phone')?>" /></p>
						</div>
						
						<div class="_50">
							<p><label for="fax">Fax </label><input id="fax" name="fax" class="" type="text" value="<?php set_val($contact,'fax')?>" /></p>
						</div>
						
						<div class="_50">
							<p><label for="job_des">Job Title</label><input id="job_des" name="job_des" class="required" type="text" value="<?php set_val($contact,'job_des')?>" /></p>
						</div>						
						<div class="_50">
							<p><label for="website">Website</label><input id="website" name="website" class="" type="text" value="<?php set_val($contact,'website')?>" /></p>
						</div>
						
						<div class="_100">
							<p><label for="address">Address </label><textarea id="address" name="address" class="" rows="3" cols="40"><?php set_val($contact,'address')?></textarea></p>
						</div>

						
						<div class="_100">
							<p><label for="notes">Notes</label><textarea id="notes" name="notes" class="" rows="2" cols="40"><?php set_val($contact,'notes')?></textarea></p>
						</div>
						
						<div class="_100">
							<p><label for="previous_event">Previous Event</label>
							<select name="previous_event" id="previous_event" class="">
								<option value="">Select Event</option>
								<?php foreach($event_list as $event):?>
									<option <?php if(set_val($contact,'previous_event','return')==$event->id) echo 'selected="selected"';?> value="<?php echo $event->id?>"><?php echo $event->event_name?></option>
								<?php endforeach;?>
							</select>
							</p>
						</div>
						
						<div class="_100">
							<p><label for="extra">Extra</label><textarea id="extra" name="extra" class="" rows="2" cols="40"><?php set_val($contact,'extra')?></textarea></p>
						</div>

						<div class="_100">
							<p><label for="extra_2">Extra 2 </label><textarea id="extra_2" name="extra_2" class="" rows="2" cols="40"><?php set_val($contact,'extra_2')?></textarea></p>
						</div>

						<div class="_100">
							<p><label for="extra_3">Extra 3</label><textarea id="extra_3" name="extra_3" class="" rows="2" cols="40"><?php set_val($contact,'extra_3')?></textarea></p>
						</div>
						
						

						<div class="clear"></div>
						<div class="block-actions">
							<ul class="actions-left">
								<li><a class="button red" id="reset-validate-form" href="javascript:void(0);">Reset</a></li>
							</ul>
							<ul class="actions-right">
								<li><input type="submit" class="button" value="Save!"></li>
							</ul>
						</div>
					</form>
</div>



<script type="text/javascript">
	$().ready(function() {

		$("#country, #company, #previous_event").multiselect({
		   multiple: false,
		   header: "Select an option",
		   noneSelectedText: "Select an Option",
		   selectedList: 1,

		   minWidth: 300,
		   show: "slide",
		   hide: "slide"

		}).multiselectfilter();

		$("button.ui-multiselect").css('width','200px');
		$(".ui-multiselect-menu").css('width','285px');
		
		/** Submit Form **/
		$("#form").validate({
				rules:{},
				messages: {},
				submitHandler: function(form) {
				   //submit
				$.post("<?php echo site_url('contact/save')?>", $("#form").serialize(),
					function(data){
						if(data){
							
							newdata = $.parseJSON(data);
							
							if(newdata.error){
								Gtheme = 'error';
								
								$.each(newdata.msg, function(index) {
									$.jGrowl(newdata.msg[index], { theme: Gtheme,position:'center'  });
								});

							}
							else{
								Gtheme = 'saved';
								$.jGrowl(newdata.msg, { theme: Gtheme,position:'center'  });
								$('.a-z-list').parent().children('.block-content').slideToggle();
								a_z_list();
								$("#form").resetForm();
								<?php if($load_all_companies):?>
									temp_id = $("#id").val();
								<?php else:?>
									temp_id = $("#company").val();
									$("#dialog").dialog('close');
								<?php endif;?>
								//clear the folrm
									$("#id").val('');
									$(":input").not(":button, :submit, :reset, :hidden").each(function () {
										this.value = '';
									});
								if(newdata.id>0)
										load_info(newdata.id);
									else
										load_info(temp_id);
							}

						}
						else{
							$.jGrowl("Error!", { theme: 'error' });
						}
					});
				}
			});
		/** End Submit Form **/
		
		
		});
		
		
    </script>












